package com.accenture.agreco;

import com.accenture.agreco.beans.Libro;
import com.accenture.agreco.beans.impl.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * User: a.greco
 * Date: 31/10/12
 * Time: 17.02
 */

@Configuration
public class SchoolConfig {

    //LIBRO
    @Bean(initMethod = "setUniqueCopyId")
    @Scope("prototype")
    @Qualifier("capoclasse")
    public LibroImpl springInAction(){
        LibroImpl libro = new LibroImpl("Spring in Action");
        libro.setAutore("Craig Walls");
        libro.setEditore("Manning");
        libro.setEdizione("Third edition");
        libro.setPrezzo(36.5);
        return libro;
    }

    // STUDENTI
    @Bean
    public StudenteImpl mario(){
        StudenteImpl mario = new StudenteImpl("Mario", "Cicala", 28);
        mario.setAge(29);
        mario.setLibri(new Libro[]{springInAction()});
        // mario.setClasse(terzaF()); //AUTOWIRED
        return mario;
    }
    @Bean
    public StudenteImpl claudio(){
        StudenteImpl claudio = new StudenteImpl("Claudio", "Scandura");
        claudio.setAge(mario().getAge()*10);
        claudio.setLibri(new Libro[]{springInAction()});
        // claudio.setClasse(terzaF()); //AUTOWIRED
        return claudio;
    }
    @Bean
    public StudenteImpl manlio(){
        StudenteImpl manlio = new StudenteImpl("Manlio", "Fastioni");
        manlio.setAge(mario().getAge() * 10);
        manlio.setLibri(new Libro[]{springInAction()});
        // manlio.setClasse(terzaF());
        return manlio;
    }

    //PROFESSORI
    @Bean
    public ProfessoreImpl antonio(){
        ProfessoreImpl antonio = new ProfessoreImpl();
        antonio.setNome("Antonio");
        antonio.setCognome("Greco");
        antonio.setMateria("Informatica");
        return antonio;
    }

    //CLASSE
    @Bean
    public ClasseImpl terzaF(){
        ClasseImpl terzaF = new ClasseImpl();
        terzaF.setAnno(3);
        terzaF.setSezione('F');

        Collection<StudenteImpl> studenti = new HashSet<StudenteImpl>(3);
        studenti.add(mario());
        studenti.add(claudio());
        studenti.add(manlio());
        studenti.add(manlio());

        mario().setClasse(terzaF);
        claudio().setClasse(terzaF);
        manlio().setClasse(terzaF);

        terzaF.setStudenti(studenti);

        Map<String, ProfessoreImpl> professori = new HashMap<String, ProfessoreImpl>(1);
        professori.put("Spring", antonio());
        terzaF.setProfessori(professori);

        return terzaF;
    }

    //SCOULA
    @Bean
    public ScuolaImpl scientifico(){
        ScuolaImpl scientifico = new ScuolaImpl();
        scientifico.setNome("Archimede");
        scientifico.setTipo("Liceo Scientifico");
        scientifico.setCitta("Acireale");
        return scientifico;
    }
}
